import {createRouter,createWebHistory} from "vue-router";
import Home from "../Views/Home/index.vue";
import Header from "../Views/Header/index.vue";
import PatientList from "../Views/PatientList/index.vue";
import Dialog from "../Views/AnswerComponent/Dialog/index.vue";
import Login from "../Views/Login/index.vue";
import Message from "../Views/Message/message.vue";
import System from "../Views/Message/System/system.vue";
import Inquiry from "../Views/Message/Inquiry/inquiry.vue";
import Myimt from "../Views/BottomDom/index.vue";
import HCoin from "../Views/Message/H-Coin/H-coin.vue";
import AnswerComponent from "../Views/AnswerComponent/index.vue";
import History from "../Views/BottomDom/History/HistoryTrun.vue";
import Details from "../Views/BottomDom/FormList/fromList.vue";
import Avatar from "../Views/BottomDom/Avatar/avatar.vue";
import Recording from "../Views/BottomDom/History/Recording/Recording.vue";
import Appraise from "../Views/BottomDom/History/Appraise/Appraise.vue";
import Gift from "../Views/BottomDom/History/Gift/Gift.vue";
import AutoReplyComponent from "../Views/BottomDom/AutoReplyComponent/index.vue";
import MyComponent from "../Views/BottomDom/MyComponent/index.vue";
import Compost from "../Views/Login/PermanentStayall/Compost/index.vue";
import Purse from "../Views/BottomDom/Purse/purse.vue";
import Payout from "../Views/BottomDom/Purse/Payouts/Payouts.vue";
import Recordpayouts from "../Views/BottomDom/Purse/Payouts/Recordpayouts/Recordpayouts.vue";
import LookBind from "../Views/BottomDom/Purse/LookBind/index.vue";
import BankAmericard from "../Views/BottomDom/Purse/LookBind/BankAmericard/index.vue";
import Identification from "../Views/BottomDom/Purse/LookBind/Identification/index.vue";
import Logout from "../Views/Logout/Logout.vue";
import Settings from "../Views/Login/Forgot/SettingsPassword/settingsPassword.vue";
import Emailregistration from "../Views/Login/E-mailregistration/index.vue";
import MyText from "../Views/Login/MyText/index.vue";
import Img from "../Views/Login/Image/index.vue";
import Search from "../Views/AnswerComponent/Search/index.vue";
import Cameras from "../Views/Cameras/cameras.vue"
// 定义路由

const routes = [{
    to: "/",
  },
  {
    path: "/cameras",
    component: Cameras,

  },
  {
    path: "/Img",
    component: Img,
  },
  {
    path: "/Settings",
    component: Settings,
  },
  {
    path: "/Dialog",
    component: Dialog,
  },
  {
    path: "/MyText",
    component: MyText,
  },
  {
    path: "/Emailregistration",
    component: Emailregistration,
  },

  {
    path: "/Search",
    component: Search,
  },
  {
    path: "/History",
    component: History,
    meta: {
      requiresAuth: true,
    }, // 该路由需要认证
  },
  {
    path: "/Identification",
    component: Identification,
  },

  {
    path: "/LookBind",
    component: LookBind,
  },
  {
    path: "/BankAmericard",
    component: BankAmericard,
  },
  {
    path: "/Purse",
    component: Purse,
  },
  {
    path: "/Payout",
    component: Payout,
  },
  {
    path: "/Recordpayouts",
    component: Recordpayouts,
  },
  {
    path: "/Avatar",
    component: Avatar,
  },
  {
    path: "/Recording/:id",
    component: Recording,
    name:'Recording',
    meta: {
      requiresAuth: true,
    }, // 该路由需要认证
  },
  {
    path: "/Appraise",
    component: Appraise,
    meta: {
      requiresAuth: true,
    }, // 该路由需要认证
  },
  {
    path: "/Gift",
    component: Gift,
    meta: {
      requiresAuth: true,
    }, // 该路由需要认证
  },
  {
    path: "/Inquiry",
    component: Inquiry,
    meta: {
      requiresAuth: true,
    }, // 该路由需要认证
  },
  {
    path: "/Myimt",
    component: Myimt,
    children: [],
  },
  {
    path: "/HCoin",
    component: HCoin,
    meta: {
      requiresAuth: true,
    }, // 该路由需要认证
  },
  {
    path: "/System",
    component: System,
    meta: {
      requiresAuth: true,
    }, // 该路由需要认证
  },
  {
    path: "/Message",
    component: Message,
    meta: {
      requiresAuth: true,
    }, // 该路由需要认证
  },
  {
    path: "/header/PatientList",
    component: PatientList,
    meta: {
      requiresAuth: true,
    }, // 该路由需要认证
  },
  {
    path: "/MyComponent",
    component: MyComponent,
    meta: {
      requiresAuth: true,
    }, // 该路由需要认证
  },
  {
    path: "/Details",
    component: Details,
    meta: {
      requiresAuth: true,
    }, // 该路由需要认证
  },
  {
    path: "/AnswerComponent",
    component: AnswerComponent,
    meta: {
      requiresAuth: true,
    }, // 该路由需要认证
  },
  {
    path: "/AutoReplyComponent",
    component: AutoReplyComponent,
    meta: {
      requiresAuth: true,
    }, // 该路由需要认证
  },
  {
    path: "/login",
    component: Login,
  },
  {
    path: "/Logout",
    component: Logout,
    meta: {
      requiresAuth: true,
    }, // 该路由需要认证
  },
  {
    path: "/Compost",
    component: Compost,
  },

  {
    path: "/details",
    component: Details,
  },
  {
    path: "/header",
    component: Header,
  },
  {
    path: "/",
    component: Home,
  },
  // 其他路由
];

// 创建路由器实例
const router = createRouter({
  history: createWebHistory(
    import.meta.env.BASE_URL),
  routes,
});

// 添加全局前置守卫
router.beforeEach((to, from, next) => {
  const token = localStorage.getItem("token"); // 获取 token（或其他存储方式）

  if (to.meta.requiresAuth && !token) {
    // 如果目标路由需要认证且用户未登录，重定向到登录页
    next("/login");
  } else {
    // 允许访问王晓磊
    next();
  }
});

export default router;